package khiem.gadgets.demo.client;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.google.gwt.user.cellview.client.CellList;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.datepicker.client.DatePicker;
import com.google.gwt.view.client.ListDataProvider;

import com.google.gwt.cell.client.TextCell;
import com.google.gwt.gadgets.client.DynamicHeightFeature;
import com.google.gwt.gadgets.client.Gadget;
import com.google.gwt.gadgets.client.NeedsDynamicHeight;
import com.google.gwt.gadgets.client.UserPreferences;
import com.google.gwt.gadgets.client.Gadget.ModulePrefs;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */

//Added comments at the end of each line to break up Eclipse's auto formatting.
@ModulePrefs(
title = "newgadget", 
directory_title = "newgadget")
public class newgadget extends Gadget<UserPreferences> implements NeedsDynamicHeight {

  //The list of data to display.
  private static final List<String> DAYS = Arrays.asList("Sunday", "Monday",
                                                         "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
  
  ShowMorePagerPanel pagerPanel;
  DatePicker datePicker;
  CellList<String> cellList;
  DynamicHeightFeature heightFeature;
  
  @Override
  protected void init(UserPreferences preferences) {
    VerticalPanel vPanel = new VerticalPanel();
    
    // Create a cell to render each value in the list.
    TextCell textCell = new TextCell();
    cellList = new CellList<String>(textCell);
    cellList.setPageSize(30);
    
    // Add a cellList to a data provider.
    ListDataProvider<String> dataProvider = new ListDataProvider<String>();
    List<String> data = dataProvider.getList();
    for (int i = 0; i < 200; i++) {
      data.add("Item " + i);
    }
    dataProvider.addDataDisplay(cellList);

    // Create a SimplePager.
    //SimplePager pager = new SimplePager();
    ShowMorePagerPanel pager = new ShowMorePagerPanel();

    // Set the cellList as the display.
    pager.setDisplay(cellList);
    
    datePicker = new DatePicker();
    // Set the default value
    datePicker.setValue(new Date(), true);
    
    vPanel.add(datePicker);
    vPanel.add(cellList);
    vPanel.add(pager);
    RootPanel.get().add(vPanel);
    heightFeature.adjustHeight();
  }

  /* (non-Javadoc)
   * @see com.google.gwt.gadgets.client.NeedsDynamicHeight#initializeFeature(com.google.gwt.gadgets.client.DynamicHeightFeature)
   */
  public void initializeFeature(DynamicHeightFeature feature) {
    this.heightFeature = feature;
  }
  
}
